2.Group Assignment: probe an input device's analog levels and digital signals
3.Individual Assignment:
Files:
Tools:
Credit: Robert Hart
//tx_rx03 Robert Hart Mar 2019.
//https://roberthart56.github.io/SCFAB/SC_lab/Sensors/tx_rx_sensors/index.html
//Modified by Adrián Torres Omaña
//Fab Academy 2021
//Step Response TX, RX
//Adrianino
//ATtiny1614
// Program to use transmit-receive across space between two conductors.
// One conductor attached to digital pin, another to analog pin.
//
// This program has a function "tx_rx() which returns the value in a long integer.
//
// Optionally, two resistors (1 MOhm or greater) can be placed between 5V and GND, with
// the signal connected between them so that the steady-state voltage is 2.5 Volts.
//
// Signal varies with electric field coupling between conductors, and can
// be used to measure many things related to position, overlap, and intervening material
// between the two conductors.
//
long result; //variable for the result of the tx_rx measurement.
int analog_pin = 1; // PA5 of the ATtiny1614
int tx_pin = 2; // PA6 of the ATtiny1614
void setup() {
pinMode(tx_pin,OUTPUT); //Pin 2 provides the voltage step
Serial.begin(115200);
}
long tx_rx(){ //Function to execute rx_tx algorithm and return a value
//that depends on coupling of two electrodes.
//Value returned is a long integer.
int read_high;
int read_low;
int diff;
long int sum;
int N_samples = 100; //Number of samples to take. Larger number slows it down, but reduces scatter.
sum = 0;
for (int i = 0; i < N_samples; i++){
digitalWrite(tx_pin,HIGH); //Step the voltage high on conductor 1.
read_high = analogRead(analog_pin); //Measure response of conductor 2.
delayMicroseconds(100); //Delay to reach steady state.
digitalWrite(tx_pin,LOW); //Step the voltage to zero on conductor 1.
read_low = analogRead(analog_pin); //Measure response of conductor 2.
diff = read_high - read_low; //desired answer is the difference between high and low.
sum += diff; //Sums up N_samples of these measurements.
}
return sum;
} //End of tx_rx function.
void loop() {
result = tx_rx();
result = map(result, 8000, 11000, 0, 1024); //I recommend mapping the values of the two copper plates, it will depend on their size
Serial.println(result);
delay(100);
}
I programmed my microntroller using UPDI pin, with the help of megaTinyCore library, and I used UPDI + VCC module.
int inPin = 10;
int outPin = 0;
int state = HIGH;
int reading;
int previous = LOW;
long time = 0;
long debounce = 200;
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(outPin, state);
previous = reading;
}
#include
int trigPin = 3; //Trig Pin for Ultrasonic Sensor
int echoPin = 2; //Echo Pin for Ultrasonic Sensor
int ledPin = 0;
long duration;
int cm;
char cstr[16];
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
pinMode(trigPin, OUTPUT); //Set Ultrasonic Trigger Pin as OUTPUT
pinMode(echoPin, INPUT); //Set Ultrasonic Echo Pin as INPUT
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW); //Write it to LOW
delayMicroseconds(2); // Wait for 2mus
digitalWrite(trigPin, HIGH); // Write the Trig Pin to HIGH
delayMicroseconds(10); // Wait for 10mus
digitalWrite(trigPin, LOW);// Write the Trig Pin to LOW
duration = pulseIn(echoPin, HIGH); //The duration the echoPin takes to go HIGH in microseconds
cm = microsecondsToCentimeters(duration);
sprintf(cstr, "%03d", cm);
Serial.println(cm);
delay(500);
}
long microsecondsToCentimeters(long microseconds){
return (microseconds / 29.15 ) / 2;
}
void requestEvent() {
Wire.write(cstr);
}
int pin = 0;
int value = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
value = analogRead(pin);
Serial.println(value);
delay(500);
}
Same as Hall-Effect Sensor...
Neil's breakout board was used: here
As a group assignment, we probed hall sensor where the character of the hall sensor was visualized in the digital oscilloscope.
First the 5V is given from the Programmable DC Power Supply to the hall sensor and then, first set the oscilloscope to DC supply. Then autoset the oscilloscope. After there is a green liight in the Run/Stop, place the black wire to the ground and the vcc to the vout of the hall sensor.
Now after the circuit is completed, get a magnet and put it close to the hall sensor. You will notice that when you move your magnet closer to the sensor, there is a oscillation and when it is released suddenly, there is a immediate oscillation in opposite direction. Similarly, when you bring one surface of a magnet closer it oscillates and if the magnet is flipped, the signal is also in the opposite direction.