Sensor module code
int moisture_pin = A1;
// //int microphone_dpin = D7;, not using
int microphone_apin = A0;
int light_sensor_pin = A2;
int moisture_level, mic_level, light_level;
char *buffer;
void setup() {
moisture_level = 255;
mic_level = 255;
light_level = 0;
// //Serial.begin(9600);
pinMode(moisture_pin, INPUT);
pinMode(light_sensor_pin, INPUT);
pinMode(microphone_apin, INPUT_PULLDOWN);
buffer = (char*)calloc(200, sizeof(char));
}
void loop() {
moisture_level = (255 - max(0, min(255, analogRead(moisture_pin) / 8)));
mic_level = 255 - max(0, min(analogRead(microphone_apin) / 8, 255));
//mic_level = 255 - max(0, min(255, map(analogRead(microphone_apin), 0, 4095, 0, 255)));
light_level = max(0, min(255, analogRead(light_sensor_pin) / 4));
//char buffer[200];
sprintf(buffer, "moisture = %d, micval %d, lightlevel = %d", moisture_level, mic_level, light_level);
Particle.publish("data", buffer, PRIVATE, WITH_ACK);
delay(2000);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .