Assignment

Measure the analog levels and digital signals in an input device

Analog Read

For this group assignment we decided to test analog and digital signals coming from a Water Flow Sensor. The code uploaded in our board (Link) is:

      
#include <SoftwareSerial.h>
#define rxPin 2
SoftwareSerial serial(10, rxPin);
int analogPin = 3;    
                       
int val = 0;           

void setup(){
serial.begin(9600);              //  setup serial
}

void loop(){
val = analogRead(analogPin);     // read the input pin
serial.println(val);             // debug value
}
      
      
So, opening the Arduino IDE serial monitor and setting 9600 as baud rate, the situation in front of us is the following one:

It gives us values between 5 and 1024, printing it in a new line inside the serial monitor. This range is given by the analog to digital convertion (ADC) resolution, that is about 10-bit (ATtiny45 datasheet).

Digital Read

We changed and upload another sketch, modifying analogRead in digitalRead.
      
#include <SoftwareSerial.h>
#define rxPin 2
SoftwareSerial serial(10, rxPin);
int digitalPin = 3;    
                       
int val = 0;           

void setup(){
serial.begin(9600);              //  setup serial
}

void loop(){
val = digitalRead(digitalPin);     // read the input pin
serial.println(val);             // debug value
}
      
    



It obviusly gives us only 0 or 1 values. This because it reads only the status changing, from 0 (LOW) to 1 (HIGH). For this kind of sensor, this code doesn't make sense, because they are made to measure, in this particular case, the amount of water passing through it and a digital read couldn't quantify it.

Oscilloscope Test




After properly wiring the flow sensor to the oscilloscope, we tried to blow on it to see if at there were any kind of state changes on it while operating




What we were able to see was a steep change of tension as soon as the fan inside the sensor was moving.




The resulting current from the sensor was stable and precise, a behaviour that was totally expected since the it's its way of communicating a fluid passing through it.
As soon as the fan stopped moving, the oscilloscope once again reported a flat line of inactivity.