5 LED Blink void setup forint i 2
(5 LED Blink) void setup() { for(int i = 2; i < 7; i++) { pin. Mode(i, OUTPUT); } } void loop() { for(int i = 2; i < 7; i++) { digital. Write(i, HIGH); delay(25); digital. Write(i, LOW); } for(int i = 5; i > 2; i--) { digital. Write(i, HIGH); delay(20); digital. Write(i, LOW); } }
int red. Led. Delay = 10000; int green. Led. Delay = 10000; int red. Led = 7; int yellow. Led = 6; int green. Led = 5; void setup() { pin. Mode(red. Led, OUTPUT); pin. Mode(yellow. Led, OUTPUT); pin. Mode(green. Led, OUTPUT); } void loop() { digital. Write(red. Led, HIGH); delay(red. Led. Delay); digital. Write(yellow. Led, HIGH); delay(2000); digital. Write(red. Led, LOW); digital. Write(yellow. Led, LOW); digital. Write(green. Led, HIGH); delay(green. Led. Delay); digital. Write(yellow. Led, HIGH); digital. Write(green. Led, LOW); delay(2000); digital. Write(yellow. Led, LOW); }
void setup() { PWM Program pin. Mode(5, OUTPUT); } void loop() { for (int i = 0; i < 256; i ++) { analog. Write(5, i); delay(10); } delay(200); for (int i = 255; i > 0; i --) { analog. Write(5, i); delay(10); }
TEMPERATURE SENSOR WITH ARDUINO int val; int temp. Pin = 1; void setup() { Serial. begin(9600); } void loop() { val = analog. Read(temp. Pin); float mv = ( val/1024. 0)*5000; float cel = mv/10; float farh = (cel*9)/5 + 32; Serial. print("TEMPRATURE = "); Serial. print(cel); Serial. print("C"); Serial. println(); delay(1000); /* uncomment this to get temperature in farenhite Serial. print("TEMPRATURE = "); Serial. print(farh); Serial. print("F"); Serial. println(); */ }
Sample Program
#include <dht. h> <Code/> #define dht_dpin A 1 //no ; here. Set equal to channel sensor is on dht DHT; void setup(){ Serial. begin(9600); delay(300); //Let system settle Serial. println("Humidity and temperaturenn"); delay(700); //Wait rest of 1000 ms recommended delay before //accessing sensor } //end "setup()" void loop() { //This is the "heart" of the program. DHT. read 11(dht_dpin); Serial. print("Current humidity = "); Serial. print(DHT. humidity); Serial. print("% "); Serial. print("temperature = "); Serial. print(DHT. temperature); Serial. println("C "); delay(800); //Don't try to access too frequently. . . in theory should be once per two seconds, fastest,
#include <Liquid. Crystal. h> int reading = 0; int sensor. Pin = A 0; int relay =7; // initialize the library with the numbers of the interface pins Liquid. Crystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd. begin(16, 2); pin. Mode(relay, OUTPUT); } void loop() { reading = analog. Read(sensor. Pin); int celsius = reading/2; lcd. set. Cursor(0, 0); lcd. print("Temperature is: "); lcd. set. Cursor(0, 1); lcd. print(celsius, DEC); lcd. print((char)223); lcd. print("C"); if (celsius >35) { digital. Write(7, HIGH); } else { digital. Write(7, LOW); } delay(500); lcd. clear(); }
- Slides: 7