Arduino Bluetooth Nunchuck
02/10/2021 | Views: 2350 | Arduino | by: ELECTRONOOBS      

I will use a Wii console Nunchuck to get the movement from the Joystiock and send the data using the Bluetooth module. This actuallly has an i2c communication, so you might use that to read the values of the joystick if you want. The schematic would be something like you have below with a battery and a switch, the Arduino, the joystick analog outputs and the Bluetooth module.

Part 2 - What we need

tutorial homemade arduino nunchuck bluetooth

Part 2 - Schematic

schematic arduino hc 05 nunchuck controller bluetooth

Part 3 - The Controller Code

/* This code is for the balancing robot Bluetooth controller. You can find more about this on 
 * Kind thanks to Joop Brokking for the help: 
 * Tutorial: */

byte Byte_to_send;                                    //We store here the data to send
int JoystickX_IN = A0;                                //Input from the X axis joystick
int JoystickY_IN = A1;                                //Input from the Y axis joystick

void setup(){
  Serial.begin(9600);                                 //Start the serial port at 9600 kbps  
  pinMode(JoystickX_IN, INPUT);                       //Declare the pin as INPUT
  pinMode(JoystickY_IN, INPUT);                       //Declare the pin as INPUT
  delay(20);                                          //Short delay

void loop(){
  Byte_to_send = B00000000; 
  int joystick_x = analogRead(JoystickX_IN);
  int joystick_y = analogRead(JoystickY_IN);

  if(joystick_x < 80) Byte_to_send |= B00000001;      //Rotate Left
  if(joystick_x > 170)Byte_to_send |= B00000010;      //Rotate Right
  if(joystick_y < 80) Byte_to_send |= B00001000;      //Forward 
  if(joystick_y > 170)Byte_to_send |= B00000100;      //Backward
  if(Byte_to_send)Serial.print((char)Byte_to_send);   //Send the send_byte variable if it's value is larger then 0
  delay(40);                                          //Create a 40 millisecond loop delay

02/10/2021 | Views: 2350 | Arduino | by: ELECTRONOOBS      

Last tutorials

ESP32 IOT and Arduino Database + POST method
Coin Selector With Arduino and Magnetic Disturbance
Homemade Arduino GRBL CNC Vinyl cutter
Arduino - EEPROM
Full Vacuum Tube Audio Amplifier 6W + 6W - Dose it sound good?



PCBWAY PCB service

Curso Arduino Online nivel Intermedio