Guest User

Untitled

a guest
Nov 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. /*
  2. ReadAnalogVoltage
  3. Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  4. Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  5.  
  6. This example code is in the public domain.
  7. */
  8.  
  9. // the setup routine runs once when you press reset:
  10. void setup() {
  11. // initialize serial communication at 9600 bits per second:
  12. Serial.begin(9600);
  13. }
  14.  
  15. // the loop routine runs over and over again forever:
  16. void loop() {
  17. // read the input on analog pin 0:
  18. int sensorValue = analogRead(A0);
  19. // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  20. float voltage = sensorValue * (5.0 / 1023.0);
  21. // print out the value you read:
  22. int sensorValue1 = analogRead(A0) * (5.0 / 1023.0);
  23. int sensorValue2 = analogRead(A1) * (5.0 / 1023.0);
  24. int sensorValue3 = analogRead(A2) * (5.0 / 1023.0);
  25. int sensorValue4 = analogRead(A3) * (5.0 / 1023.0);
  26.  
  27. if (sensorValue1 == 5)
  28. {
  29. Serial.println("sensor 1");
  30. delay(200);
  31. }
  32.  
  33. if (sensorValue2 == 5)
  34. {
  35. Serial.println("sensor 2");
  36. delay(200);
  37. }
  38.  
  39. if (sensorValue3 == 5)
  40. {
  41. Serial.println("sensor 3") ;
  42. delay(200);
  43. }
  44.  
  45. if (sensorValue4 == 5)
  46. {
  47. Serial.println("sensor 4") ;
  48. delay(200);
  49. }
  50. delay(50);
  51. }
Add Comment
Please, Sign In to add comment