Advertisement
safwan092

Energy Stick Arduino Code

Dec 27th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1.  
  2. int sum = 0;
  3.  
  4. void setup() {
  5.   // initialize serial communication at 9600 bits per second:
  6.   Serial.begin(9600);
  7.   pinMode(7, OUTPUT);
  8.   digitalWrite(7, LOW);
  9. }
  10.  
  11. // the loop routine runs over and over again forever:
  12. void loop() {
  13.  
  14.  
  15.  
  16.   for (int i = 0; i <= 10; i++) {
  17.   int sensorValue = analogRead(A0);
  18.     sum = sum + sensorValue;
  19.  
  20.   }
  21.   if (sum <= 3) {
  22.     digitalWrite(7, HIGH);
  23.     Serial.println(sum);
  24.     delay(2);
  25.     sum = 0;
  26.   }
  27.   else {
  28.  
  29.     digitalWrite(7, LOW);
  30.     Serial.println(sum);
  31.     sum = 0;
  32.   }
  33.  
  34.   delay(1);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement