Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_ssd1306syp.h>
- #include <math.h>
- #define SDA_PIN A4
- #define SCL_PIN A5
- const int analogInPin = A2;
- float sensorValue = 0;
- int moist = 0;
- Adafruit_ssd1306syp display(SDA_PIN,SCL_PIN);
- void setup() {
- Serial.begin(9600);
- delay(1000);
- display.initialize();
- }
- float readMoisture(){
- float tmpVal=0;
- for (int i=0; i <= 25; i++){
- tmpVal+=analogRead(analogInPin);
- delay(10);
- }
- return (tmpVal / 25);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- sensorValue = readMoisture();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(20,0);
- display.println("Moisture");
- display.setTextColor(WHITE);
- display.setCursor(38,18);
- display.println("Level");
- Serial.print("Raw: ");
- Serial.println(sensorValue);
- moist=map(sensorValue, 0, 1023, 0, 100);
- Serial.print(moist);
- Serial.println("%");
- if (moist < 10) {
- display.setCursor(48,40);
- }else if(moist < 100){
- display.setCursor(40,40);
- }else{
- display.setCursor(32,40);
- }
- display.print(moist);
- display.println("%");
- display.update();
- delay(1000);
- display.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement