Paul Sutton

Personal Blog

Code Club Electronics 12

So the next project is to try and link the potentiometer value to a buzzer tone.

So, using some tutorial code for the buzzer here. I have tried to modify to change the tone of the buzzer depending on the value from the potentiometer.

// the setup function runs once when you press reset or power the board

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
const int buzzer = 5;


void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(buzzer, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);
  tone(buzzer, 1000);   // 1khz tone to buzzer
  delay(analogValue);                       // wait for time period linked to pot input value
  tone(buzzer, 1000);    // 1khz tone to buzzer

  //https://www.instructables.com/How-to-use-a-Buzzer-Arduino-Tutorial/
}

What I have now is a little buggy, If I bind the actual pot value between 0 and 1023, anything below 20hz is inaudible, so that the frequency is within the human hearing range (20hz – 20khz)

Not quite sure what is going to work, sharing this as work in progress.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

CRISPR

Interesting article about an announcement in relation to the gene editing technique(s) known as CRISPR.

Today, we talk about the much-awaited CRISPR-based drug Casgevy, discuss the new Gavi initiative that plans to dramatically ramp up vaccine manufacturing in Africa, and more. Have a nice weekend!

Also, wonderful that Africa can lead the way on this, too.

Tags

#CRISPR,#Genetic,#Editing,#Vaccine,#Research,#BioTech


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club Electronics 11

I am now combining a LED blink routine, with reading the potentiometer value input.

// the setup function runs once when you press reset or power the board

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}


  

// the loop function runs over and over again forever
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(analogValue);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(analogValue);                       // wait for a second
}

Video

Video illustrates how rotation of the potentiometer is reflected in the LED blink delay.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club Electronics 10

So following on from the previous post. Still using the Easy module shield) I have found out how to read the analogue input from the potentiometer. So far this gives a value and voltage.

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer
 */

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Voltage: ");
  Serial.println(voltage);
  delay(1000);
}

So the two lines (the first is a comment) sets the program to read from A0

 // read the input on analog pin A0:
  int analogValue = analogRead(A0);

With output looking like

 // read the input on analog pin A0:
  int analogValue = analogRead(A0);

READING THE LIGHT SENSOR

By changing this to

 // read the input on analog pin A1:
  int analogValue = analogRead(A1);

It is possible to read the light sensor on the same board.

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer
 */

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float light = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Light: ");
  Serial.println(light);
  delay(1000);
}

I have edited the lines above so that it reflects the fact we are now reading the light sensor.

  float light = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Light: ");
  Serial.println(light);
  delay(1000);
}

You will need to change the other lines to suit, as some of the comments still refer to the potentiometer.

Video

Video illustrates how rotation of the potentiometer is reflected in the output values.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club Electronics 9

So following on from the previous post. I had to look this up to remind myself how to specific a pin.

So my next project, was to try and get the DHT11 temperature and humidity module working. I had a problem with the library for this, so looked at the code, used the section of this that used the LM35 temperature module (which can also be found on the Easy module shield)

float tempC;
int tempPin = 2;
byte temperature = 0;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature

  Serial.print("LM35 - Temperature: "); 
  Serial.print((byte)tempC);
  Serial.println(" Celcius");
  delay(500); // delay 5 seconds
}

So just switched to pin 2 above

int tempPin = 2;

And modified the code to give nicer output. The Arduno IDE allows for both plotting of data on a graph and also just using the serial monitor.

Output looks like this

LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Tinkerers – Torbay

This is a new group, formed out of the Stem group at Paignton library, it is aimed at adult tinkerers, project builders etc and hopes to bring like-minded people together.

We enjoy experimentation, Tinkering etc.

So far we have a website and a discord group, please get in touch as Discord is invite only at present.

Tags

#STEM,#Torbay,#Hacking,#Tinkerers,#Hardware,#Software,#Firmware,'Science,#Tech,#Art.#Maths,#Engineering


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club Electronics 8

So following on from the previous post. I had to look this up to remind myself how to specific a pin. Not used Arduino in a while. I found the following code as part of a stackoverflow post

However, in this, the two LEDs flash on and off alternately. Delay is set by a single line.

int delayPeriod = 1000;

So this is more so I can learn how to specify a pin.

int ledPin = 12;
int ledPin2 = 13;
int delayPeriod = 1000;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2,LOW);
  delay(delayPeriod);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin,LOW);
  delay(delayPeriod);
  //delayPeriod = delayPeriod - 10;
}

In the video, I am just changing a single line of code to cause the delay.

Timings are in milliseconds or seconds

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#LED,#Blink


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club Electronics 7

Just having a look at an Arduino add-on board, that has various inputs and outputs built in. The following code (from the default IDE library) flashes an LED on and off. The delays can be changed within the code.

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}



// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);                       // wait for 100 milli seconds
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                       // wait for 250 milli seconds
}

The video just shows the last section of code and what happens when the delay is changed.

Timings are in milliseconds or seconds

e.g. 1000 ms = 1 second 2000 ms = 2 seconds 100 ms = 0.1 seconds 250ms = 0.250 seconds (¼ second) 500ms = 0.500 seconds (½ second)

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#LED,#Blink


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Code Club 6/1/2024

The next Paignton Library code club will be on the 6th Jan 2024. We will carry on with what we were doing in previous sessions. This is mostly fixing laptops and also looking at building some electronics projects.

Useful Links

Legacy Links

Next Code Club

The next code club is 20/1/2024 : 10am to 12:00 Tags

#CodeClub,#Python,#HourOfCode,#Scratch,#Minecraft,#Themes, #Java,#Programmng


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Young Coders Competition 2024 – Information for Educators

If anyone is interested in entering the young coders contest, please consider sharing the following video with teachers etc. See if we can get a few more schools involved.

I am happy to chat on IRC about this, please see chat page. If anyone would like direct help, you can drop come along to code club and see what we can help with.

Please contact Paignton Library for details on code club.


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay