- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
In this tutorial, I will be evaluating Prextron CHAIN blocks – a new system that allows you to connect your sensors and actuators to an Arduino NANO using clever 3D-printed prototyping boards that can be stacked sideways. This very modular system makes it easy to connect, disconnect and replace project components, and eliminate the “rats nest of wires” common to many advanced Arduino projects. CHAIN BLOCKS are open, which means that you can incorporate any of your sensors or actuators to these prototyping boards, and you can decide which specific pin on Arduino you plan to use. The CHAIN BLOCK connections prevent or reduce common connection mistakes, which make them ideal for class-room projects and learning activities.
I am going to set up a project to put these CHAIN BLOCKs to the test:
When I place my hand in-front of an Ultrasonic sensor, the Arduino will transmit a signal wirelessly to another Arduino, and consequently turn on a motor.
You need the following Prextron Chain Blocks
This project does not use any libraries. However, you will need to upload Arduino code to the Arduino. For this you will need the Arduino IDE which can be obtained from the official Arduino website:
https://www.arduino.cc/en/main/software
/* =============================================================== | |
Project: CHAIN BLOCKS : HC-SR04 433MHz RF Transmitter sketch | |
Author: Scott C | |
Created: 26th Feb 2017 | |
Arduino IDE: 1.8.1 | |
Website: http://arduinobasics.blogspot.com.au | |
Description: Use a HC-SR04 ultrasonic sensor to trigger a signal to be sent via | |
a 433Mhz RF transmitter. | |
================================================================== */ | |
#define trig 3 //Connect Arduino Digital Pin3 to the Trig pin on the HC-SR04 sensor | |
#define echo 4 //Connect Arduino Digital Pin4 to the Echo pin on the HC-SR04 sensor | |
#define rfTransmit 5 //Connect Arduino Digital Pin5 to the data pin on the 433MHz RF transmitter | |
#define red 6 //Connect Arduino Digital Pin6 to the RED LED. | |
#define green 9 //Connect Arduino Digital Pin9 to the GREEN LED. | |
float TempC = 24.0; //Current Temperature will affect speed of sound. | |
float speedOfSound; | |
long duration, distance; //Duration will used to calculate the distance | |
boolean activated = false; //If distance is less than 30cm, the "activated" variable will be TRUE. | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(trig, OUTPUT); | |
pinMode(echo, INPUT); | |
pinMode(rfTransmit, OUTPUT); | |
pinMode(red, OUTPUT); | |
pinMode(green, OUTPUT); | |
} | |
void loop() { | |
activated = checkDistance(); //If distance is less than 30cm, the "activated" variable will be TRUE. | |
if(activated){ | |
digitalWrite(red,LOW); //Turn off the RED LED | |
digitalWrite(green, HIGH); //Turn on the GREEN LED | |
analogWrite(rfTransmit, 150); //Transmit a signal with a duty cycle of 150/255 via the 433Mhz transmitter | |
}else { | |
digitalWrite(green,LOW); //Turn off the GREEN LED | |
digitalWrite(red, HIGH); //Turn on the RED LED | |
analogWrite(rfTransmit, 100); //Transmit a signal with a duty cycle of 100/255 via the 433Mhz transmitter | |
} | |
delay(100); | |
} | |
/* ===================================================================== | |
* checkDistance() | |
* is a function that takes a reading from the HCSR04 ultrasonic sensor to determine the distance of an object to the sensor. | |
* When the sensor detects an object within 30cm, it will return TRUE. | |
* Otherwise it will return FALSE. | |
* ===================================================================== | |
*/ | |
boolean checkDistance(){ | |
digitalWrite(trig, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trig, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trig, LOW); | |
duration = pulseIn(echo, HIGH); | |
speedOfSound = (331.3 + (0.6*TempC)) / 10000.0; //Speed of sound in "cm per microsecond" | |
distance = (duration*speedOfSound)/2; //Calculate the distance (in cm) based on the speed of sound. | |
if(distance<30){ //When the distance detected is <30cm, it will return TRUE | |
return true; | |
} | |
return false; | |
} |
/* =============================================================== | |
Project: CHAIN BLOCKS : 433MHz Receiver with Relay and Motor | |
Author: Scott C | |
Created: 26th Feb 2017 | |
Arduino IDE: 1.8.1 | |
Website: http://arduinobasics.blogspot.com.au | |
Description: Use the 433Mhz RF receiver to receive a signal. The Arduino | |
will process this signal and will trigger a relay | |
based on the result of the signal. A motor is attached to the | |
relay for extra effect. | |
================================================================== */ | |
#define relay 10 //Connect relay module signal pin to Arduino digital pin 10 | |
long mySignal=0; //This variable holds the signal value | |
int reps = 200; //Increase the number of repetitions (Reps) for greater accuracy | |
boolean trigger = false; //The relay will switch when the "trigger" is true | |
boolean lastTrigger = false; //Hold the state of the last Trigger value | |
int threshold = 325; //If mySignal is greater than this threshold, it will trigger the relay | |
/* ================================================================ | |
* SETUP () | |
================================================================== */ | |
void setup() { | |
pinMode(relay, OUTPUT); | |
Serial.begin(9600); | |
} | |
/* ================================================================ | |
* LOOP () | |
================================================================== */ | |
void loop() { | |
mySignal = 0; //Reset this variable with every loop. | |
for(int i=0; i<reps; i++){ | |
mySignal = mySignal + analogRead(A0); | |
} | |
mySignal = mySignal / reps; //Take the average analog reading. | |
Serial.println(mySignal); //Print to the serial monitor / or plotter. | |
if(mySignal>threshold){ //If mySignal is greater than the threshold, it will trigger the relay | |
trigger = true; | |
} else { | |
trigger = false; | |
} | |
if(trigger==lastTrigger){ | |
//do nothing if the current trigger is the same as the last trigger. | |
}else { | |
digitalWrite(relay, trigger); //The state of the relay will reflect that of the trigger value | |
delay(200); //The 200ms delay is necessary for stability reasons, DO NOT DELETE | |
lastTrigger=trigger; //Keep track of the state of the current trigger. | |
} | |
} |
The purpose of this project was to evaluate Prextron CHAIN BLOCKs and put them to the test. Here is what I thought of CHAIN BLOCKS at the time of evaluation. Some of my points mentioned below may no longer apply to the current product. It may have evolved / improved since then. So please take that into consideration
Thank you very much to Prextron for providing the CHAIN BLOCKS used in this tutorial, and allowing me to try out their product. If you are interested in trying them yourself, then make sure to visit them at:
Comments
Post a Comment